<%--
  Created by IntelliJ IDEA.
  User: Dell
  Date: 2022/7/4
  Time: 14:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page import="mybatis.pojo.Page" %>
<%@ page import="mybatis.pojo.Subject" %>
<%@ page import="mybatis.services.GradeService" %>
<%@ page import="mybatis.services.SubjectService" %>
<%@ page import="mybatis.util.StrUtil" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市账单管理系统</title>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<%@include file="checkLogin.jsp" %>
<!--主体内容-->
<section class="publicMian ">

    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>课程管理</span>
        </div>
        <%
            String subname = request.getParameter("subName");
            subname = subname == null ? "" : subname;
            int pageNo = StrUtil.toInt(request.getParameter("pageNo"), 1);

        %>
        <div class="search">
            <form action="subject.jsp" method="post" id="seachForm">
                <input type="hidden" name="pageNo" id="pageNo" value="<%=pageNo%>">
                <span>课程名称名称：</span>
                <input type="text" placeholder="请输入课程的名称" value="<%=subname%>" name="subName"/>
                <input type="submit" value="查询"/>
            </form>
            <a href="SubjectAdd.jsp">添加</a>
        </div>

        <!--供应商操作表格-->
        <table class="providerTable" cellpadding="0" cellspacing="0">
            <tr class="firstTr">
                <th width="10%">编号</th>
                <th width="20%">课程名</th>
                <th width="10%">课时</th>
                <th width="10%">年级</th>
                <th width="30%">操作</th>
            </tr>
            <%
                Page<Subject> p = SubjectService.ME.paging(pageNo, subname);
                for (Subject s : p.getDatas()) {
            %>
            <tr>
                <td><%=s.getId()%>
                </td>
                <td><%=s.getSubjectname()%>
                </td>
                <td><%=s.getClasshour()%>
                </td>
                <td><%= GradeService.ME.find((int) s.getGradeid()).getGname()%>
                </td>
                <td>
                    <a href="providerView.html"><img src="img/read.png" alt="查看" title="查看"/></a>
                    <a href="subjectUpdate.jsp?suBid=<%=s.getId()%>"><img src="img/xiugai.png" alt="修改" title="修改"/></a>
                    <a href="subjectDelete.jsp?id=<%=s.getId()%> " class="removeProvider"
                       onclick="return confirm('确认是否删除')"><img src="img/schu.png" alt="删除" title="删除"/></a>
                </td>
            </tr>
            <%}%>
        </table>
        <p align="center" class="pager">
            <a href="#" id="prev" data-page="1">首页</a>
            <%
                if (pageNo > 1) {
            %>
            <a href="#" id="prev" data-page="<%=pageNo-1%>">上一页</a>
            <%}%>   <input type="number" name="pa" value="<%=pageNo%>" style="..." size="4" min="1"
                           max="<%=p.getTotalPages()%>">/<%=p.getTotalPages()%>
            <button type="button" id="gotoPage">Go</button>
            <% if (pageNo < p.getTotalPages()) {%>
            <a href="#" id="next" data-page="<%=pageNo+1%>">下一页</a>
            <%}%>
            <a href="#" id="next"  data-page="<%=p.getTotalPages()%>">尾页</a>

        </p>

    </div>
</section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeProv">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该供应商吗？</p>
            <a href="#" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>
<script src="js/jquery.js">
</script>
<script>
    $(function () {
        $("form#seachForm :submit").click(function () {
            $("#pageNo").val(1);//每次搜索，页号从1开始
            return true;
        });
        $(".pager #gotoPage").click(function () {
            let pageNo = $(this).prev().val();
            if (pageNo < 1 || pageNo ><%=p.getTotalPages()%>) {
                alert("页数有误")
                return false;
            }
            $("form#seachForm #pageNo").val(pageNo);
            $("form#seachForm").submit();//手工提交表单
            return false;
        });
        $(".pager a").click(function () {
            let pageNo = $(this).data("page");
            $("#pageNo").val(pageNo);
            $("form#seachForm").submit();//手工提交表单
            return false;//让a 链接失效
        });
    });
</script>
</body>
</html>
